home *** CD-ROM | disk | FTP | other *** search
/ Programming Windows 95 with MFC / Programming Windows 95 with MFC (Microsoft Programming Series)(097-0001465)(1996).iso / CODE / Chap09 / Paint6 / MainFrame.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-05  |  2.6 KB  |  96 lines

  1. //***********************************************************************
  2. //
  3. //  MainFrame.cpp
  4. //
  5. //***********************************************************************
  6.  
  7. #define OEMRESOURCE
  8.  
  9. #include <afxwin.h>
  10. #include <afxext.h>
  11. #include "Resource.h"
  12. #include "CLine.h"
  13. #include "Splitter.h"
  14. #include "MainFrame.h"
  15. #include "Paint6Doc.h"
  16. #include "TextView.h"
  17.  
  18. IMPLEMENT_DYNCREATE (CMainFrame, CFrameWnd)
  19.  
  20. BEGIN_MESSAGE_MAP (CMainFrame, CFrameWnd)
  21.     ON_WM_CREATE ()
  22.     ON_WM_MEASUREITEM ()
  23.     ON_WM_DRAWITEM ()
  24. END_MESSAGE_MAP ()
  25.  
  26. int CMainFrame::OnCreate (LPCREATESTRUCT lpcs)
  27. {
  28.     if (CFrameWnd::OnCreate (lpcs) == -1)
  29.         return -1;
  30.  
  31.     CMenu* pMenu = GetMenu ();
  32.     for (int i=0; i<8; i++)
  33.         pMenu->ModifyMenu (ID_COLOR_BLACK + i,
  34.             MF_BYCOMMAND | MF_OWNERDRAW, ID_COLOR_BLACK + i);
  35.     return 0;
  36. }
  37.  
  38. BOOL CMainFrame::OnCreateClient (LPCREATESTRUCT lpcs,
  39.     CCreateContext* pContext)
  40. {
  41.     if (!m_wndSplitter1.CreateStatic (this, 1, 2) ||
  42.         !m_wndSplitter1.CreateView (0, 0, RUNTIME_CLASS (CTextView),
  43.             CSize (160, 0), pContext) ||
  44.         !m_wndSplitter2.Create (&m_wndSplitter1, 2, 1, CSize (1, 1),
  45.             pContext, WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL |
  46.             SPLS_DYNAMIC_SPLIT, m_wndSplitter1.IdFromRowCol (0, 1)))
  47.         return FALSE;
  48.  
  49.     return TRUE;
  50. }
  51.  
  52. void CMainFrame::OnMeasureItem (int nIDCtl, LPMEASUREITEMSTRUCT lpmis)
  53. {
  54.     lpmis->itemWidth = ::GetSystemMetrics (SM_CYMENU) * 4;
  55.     lpmis->itemHeight = ::GetSystemMetrics (SM_CYMENU);
  56. }
  57.  
  58. void CMainFrame::OnDrawItem (int nIDCtl, LPDRAWITEMSTRUCT lpdis)
  59. {
  60.     BITMAP bm;
  61.     CBitmap bitmap;
  62.     bitmap.LoadOEMBitmap (OBM_CHECK);
  63.     bitmap.GetObject (sizeof (bm), &bm);
  64.  
  65.     CDC dc;
  66.     dc.Attach (lpdis->hDC);
  67.  
  68.     CBrush* pBrush = new CBrush (::GetSysColor ((lpdis->itemState &
  69.         ODS_SELECTED) ? COLOR_HIGHLIGHT : COLOR_MENU));
  70.     dc.FrameRect (&(lpdis->rcItem), pBrush);
  71.     delete pBrush;
  72.  
  73.     if (lpdis->itemState & ODS_CHECKED) {
  74.         CDC dcMem;
  75.         dcMem.CreateCompatibleDC (&dc);
  76.         CBitmap* pOldBitmap = dcMem.SelectObject (&bitmap);
  77.  
  78.         dc.BitBlt (lpdis->rcItem.left + 4, lpdis->rcItem.top +
  79.             (((lpdis->rcItem.bottom - lpdis->rcItem.top) -
  80.             bm.bmHeight) / 2), bm.bmWidth, bm.bmHeight, &dcMem,
  81.             0, 0, SRCCOPY);
  82.  
  83.         dcMem.SelectObject (pOldBitmap);
  84.     }
  85.  
  86.     pBrush = new CBrush (CPaintDoc::m_crColors[lpdis->itemID -
  87.         ID_COLOR_BLACK]);
  88.     CRect rect = lpdis->rcItem;
  89.     rect.DeflateRect (6, 4);
  90.     rect.left += bm.bmWidth;
  91.     dc.FillRect (rect, pBrush);
  92.     delete pBrush;
  93.  
  94.     dc.Detach ();
  95. }
  96.